/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode swapPairs(ListNode head) {
        if (head == null || head.next == null) return head;
        ListNode realHead = new ListNode();
        realHead.next = head;
        ListNode cur = realHead;
        while (cur.next != null && cur.next.next != null) {
            ListNode newNode = cur.next;
            cur.next = newNode.next;
            newNode.next = newNode.next.next;
            cur.next.next = newNode;
            cur = newNode;
        }
        return realHead.next;
    }
}